<?php

namespace App\Http\Requests\Orders;

use Illuminate\Foundation\Http\FormRequest;

class BookTicketRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            "mobile"                      => "required|phone",
            "orders"                      => "required|array",
            "orders.*.train_code"         => "required",
            "orders.*.from_code"          => "required",
            "orders.*.to_code"            => "required",
            "orders.*.from_name"          => "required",
            "orders.*.to_name"            => "required",
            "orders.*.from_name_uy"       => "required",
            "orders.*.to_name_uy"         => "required",
            "orders.*.seat_type"          => "required",
            "orders.*.start_at"           => "required|date|after_or_equal:today",
            "orders.*.arrive_at"          => "required|date|after_or_equal:today",
            "orders.*.trip_type"          => "required|in:1,2",
            "orders.*.transfer_flag"      => "required|in:0,1,2",
            "passengers"                  => "required|array",
            "passengers.*.truename"       => "required",
            "passengers.*.passenger_id"   => "required",
            "passengers.*.identity_type"  => "required",
            //            "passengers.*.identity_code"  => "required|passengers_identify_number:identity_type",
            "passengers.*.identity_code"  => "required",
            "passengers.*.mobile"         => "required|phone",
            "passengers.*.passenger_type" => "required",
        ];
        return $rules;
    }

    public function messages()
    {
        return [
//            "passengers.*.identity_code.passengers_identify_number" => "证件号格式错误",
"mobile.phone"              => "手机号格式错误",
"passengers.*.mobile.phone" => "手机号格式错误",
        ];
    }
}
